/*
 * @Description: 
 * @Author: xuechengwu
 * @Email: xuechengwu@myhexin.com
 * @Date: 2021-11-20 17:02:13
 * @LastEditTime: 2022-02-09 10:26:30
 * @LastEditors: xuechengwu
 */
import Vue from 'vue';
const components = {};
const A5 = {
    registerComponent(name, component, config, group = '基础') {
        console.log('component==>', component);
        if (!components[group]) {
            components[group] = [];
        }
        const componentIndex = components[group].findIndex(vo => vo.name === name);
        if (componentIndex >= 0) {
            components[group].splice(componentIndex, 1);
        }
        components[group].push({
            name,
            config,
        });
        Vue.component(name, component);
    },
    getComponent(name, group) {
        if (group) {
            return components[group] ? components[group].find(vo => vo.name === name) : {};
        } else {
            let targetComponent = null;
            const keys = Object.keys(components);
            for (let i = 0; i < keys.length; i += 1) {
                const groupComponents = components[keys[i]];
                targetComponent = groupComponents.find(vo => vo.name === name);
                if (targetComponent != null) {
                    break;
                }
            }
            return targetComponent;
        }
        
    },
    getComponents(group = '基础') {
        return components[group] || [];
    },
    log(message) {
        console.log('A5 log:', message);
    }
};

export default A5;